package dev;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class Test_Mail extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {

		
		String msgBody = "Every 2 minutes yeah yeah XD (brut text ^^)" ;
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		//UserService userService = UserServiceFactory.getUserService();
		//User user = userService.getCurrentUser();
	
		
		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress("k.kaldas91@gmail.com", "K.Kaldas"));
			msg.addRecipient(Message.RecipientType.TO,
					new InternetAddress("k.kaldas91@gmail.com", "K.Kaldas"));
			msg.setSubject("Yeah ! It fuckin' works !!!");
			msg.setText(msgBody);
			Transport.send(msg);
//			req.getRequestDispatcher("index.jsp?recherche="+adresse).forward(req, resp);

		} catch (AddressException e) {
			// ...
		} catch (MessagingException e) {
			// ...
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}